package com.aaa.stock.service.impl;

import com.aaa.entity.stock.Stock;
import com.aaa.entity.system.Dept;
import com.aaa.stock.mapper.StockMapper;
import com.aaa.stock.service.StockService;
import com.aaa.vo.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aaa
 * @since 2020-11-28
 */
@Service
public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements StockService {
    @Autowired
    private StockMapper stockMapper;
    @Override
    public Stock selectStockByComBarOriLo(String commoditybar, String locatorcode,Long warehouseid) {
        QueryWrapper<Stock> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("commoditybar",commoditybar);
        queryWrapper.eq("locatorcode",locatorcode);
        queryWrapper.eq("warehouseid",warehouseid);
        Stock stock = stockMapper.selectOne(queryWrapper);
        return stock;
    }

    @Override
    public R searchStock(Integer page, Integer limit, Stock stock) {

        Page<Stock> pageinfo=new Page<>(page,limit);
        String commoditybar=stock.getCommoditybar();
        String commodityname=stock.getCommodityname();
        String locatorcode=stock.getLocatorcode();
        String locatorname=stock.getLocatorname();
        QueryWrapper<Stock> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(commoditybar)){
            queryWrapper.like("commoditybar",commoditybar);
        }
        if(StringUtils.isNotEmpty(commodityname)){
            queryWrapper.like("commodityname",commodityname);
        }
        if(StringUtils.isNotEmpty(locatorcode)){
            queryWrapper.like("locatorcode",locatorcode);
        }
        if(StringUtils.isNotEmpty(locatorname)){
            queryWrapper.like("locatorname",locatorname);
        }
        queryWrapper.eq("warehouseid",stock.getWarehouseid());
        stockMapper.selectPage(pageinfo,queryWrapper);
        return R.ok().message("查询成功").data("pageinfo",pageinfo);
    }

    @Override
    public List<Stock> selectStoCom() {
        return stockMapper.selectStoCom();
    }

    @Override
    public List<String> selectCommoditybarByWarehouseid(Long warehouseid) {
        return stockMapper.selectCommoditybarByWarehouseid(warehouseid);
    }

    @Override
    public Integer selectSumUqtyByCommoditybar(String commoditybar, Long warehouseid) {
        return stockMapper.selectSumUqtyByCommoditybar(commoditybar,warehouseid);
    }

    @Override
    public List<Stock> selectStockByCommoditybar(String commoditybar, Long warehouseid) {
        return stockMapper.selectStockByCommoditybar(commoditybar,warehouseid);
    }

    @Override
    public List<Stock> selectStockByHouse() {
        return stockMapper.selectStockByHouse();
    }

    @Override
    public Stock selectStockByCommodity(String locatorcode, String commoditybar) {
        return stockMapper.selectStockByCommodity(locatorcode,commoditybar);
    }
}
